package com.ordersystem.utils;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.UUID;

/**
 * @author : asus1020
 * @version : [v1.0]
 * @className : PageUtils
 * @description : [描述说明该类的功能]
 * @createTime : [2022/3/25 14:10]
 * @updateUser : asus1020
 * @updateTime : [2022/3/25 14:10]
 * @updateRemark : [描述说明本次修改内容]
 */
@Component
public class PageUtils {
    public  String randomFileName(String fileName){
        UUID uuid = UUID.randomUUID();
        String randomFileName= String.valueOf(uuid);
        randomFileName=randomFileName.
                replaceAll("-","").substring(1,15)+
                fileName.substring(fileName.lastIndexOf("."));
        return randomFileName;
    }
    //随机生成一个名字
    public  String randomName(){
        String firstNameStr="赵,钱,孙,李,周,吴,郑,王,冯,陈,褚,卫,蒋,沈,韩,杨,朱,秦,尤,许,何,吕,施,张,孔," +
                "曹,严,华,金,魏,陶,姜,戚,谢,邹,喻,柏,水,窦,章,云,苏,潘,葛,奚,范,彭,郎,鲁,韦,昌,马,苗,凤,花,方" +
                ",俞,任,袁,柳,酆,鲍,史,唐,费,廉,岑,薛,雷,贺,倪,汤,滕,殷,罗,毕,郝,邬,安,常,乐,于,时,傅,皮,卞,齐,康" +
                ",伍,余,元,卜,顾,孟,平,黄,和,穆,萧,尹,姚,邵,湛,汪,祁,毛,禹,狄,米,贝,明,臧,计,伏,成,戴,谈,宋,茅,庞,熊," +
                "纪,舒,屈,项,祝,董,梁";
        String lastNameStr="贤文,泽桓,良恒,彬邦,辞驰,德哲,炳允,铭鹤,延允,锐升,嘉杰,祯龙,柏琛," +
                "年星,吉海,礼信,钊帝,日骏,成康,礼翰,瑞诚,嘉辰,帝炳,锟柔,楷祯,允凡,泽裕,锋勇,仕卓," +
                "加锟,林枫,弘晖,濡喆,允勇,濡奇,潍暄,俊帆,帆起,初平,柏胤,韦澄,彬锟,祥振,嘉谷,浩权," +
                "成然,禧瑞,日涛,晖濡,骏吉,琛成,祥泽,鹏逸,睿康,锋鹤,杰濡,起诚,皓安,槐康,晓凡,欣诚," +
                "杰尧,涛禄,强轩,锟凡,芃福,楷嘉,允谷,轩瑞,杞暄,彬文,斌畅,钊海,嘉祯,凡成,禄帆,祯延," +
                "鹏晨,驰驰,铭胤,谷哲,强辞,振远,成瑞,琛炳,琛沛,澄翱,沛辰,谛诚,弘澄,祜濡,芃仕,杞海" +
                ",然吉,芃卓,逸晓,起栋,博祥,辞峰,帆喆";
        String[]firstName=firstNameStr.split(",");
        String[]lastName=lastNameStr.split(",");
        StringBuffer nameBuffer=new StringBuffer();
        Random random = new Random();
        nameBuffer.append(firstName[random.nextInt(firstName.length)]);
        nameBuffer.append(lastName[random.nextInt(lastName.length)]);
        return String.valueOf(nameBuffer);

    }
    //生成指定位数的随机字符串
    public String randomStr(int num){
        UUID uuid = UUID.randomUUID();
        String str= String.valueOf(uuid).replaceAll("-","").substring(0,num);
        return str;
    }
    public  String getSavePath(){
        ApplicationHome applicationHome = new ApplicationHome(getClass());
        String savaPath=applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath()+
                "\\src\\main\\resources\\static";
        return savaPath;
    }
    public static String generateToken(){
        UUID uuid = UUID.randomUUID();
        String token= String.valueOf(uuid).replace("-","").toUpperCase();
        return token;

    }
}
